<?php
class Hangsanxuat extends Model
{
    public function getPhoneintoProduct($param)
    {
        $sql = "SELECT * FROM dienthoai WHERE hsx_id = :id AND (dt_in_use = 1)";
        $bind = array('id' => $param);

        return $this->Db->run($sql, $bind);
    }

    public function getTenHang($id){
        $sql = "SELECT hsx_ten from hangsanxuat WHERE hsx_id = :id";
        return $this->Db->executeScalar($sql, array('id' => $id));
    }

    # lấy tên hãng sản xuất dựa vào Id
    public static function getName($id)
    {
        $hsx = new Hangsanxuat();
        return $hsx->getTenHang($id);
    }

    # Lấy danh sách hãng sản xuât
    public static function getList()
    {
        return self::$_database->run('SELECT * FROM hangsanxuat WHERE hsx_in_use = 1');
    }

    public static function getAll()
    {
        return self::$_database->run('SELECT * FROM hangsanxuat');
    }

    public static function add($hsx_ten)
    {
        self::$_database->insert('hangsanxuat', array('hsx_ten' => $hsx_ten));
    }
    public static function update($hsx_ten, $hsx_id)
    {
        self::$_database->run("update hangsanxuat SET hsx_ten=:ten WHERE hsx_id=:id", array('ten'=>$hsx_ten, 'id'=>$hsx_id));
    }
    public  function delete($hsx_id)
    {

        self::$_database->run("update hangsanxuat SET hsx_in_use=0 WHERE hsx_id=:id",array( 'id'=>$hsx_id));
    }
    public  function restore($hsx_id)
    {

        self::$_database->run("update hangsanxuat SET hsx_in_use=1 WHERE hsx_id=:id",array( 'id'=>$hsx_id));
    }


    # lấy thông tin của hãng sản xuất dựa vào Id
    public  function getInfo($id)
    {
        $hsx = $this->Db->run("select* from hangsanxuat where hsx_id=:id", array('id'=>$id));
        if(count($hsx) > 0)
        {
            return $hsx[0]['hsx_ten'];
        }
        else
            return false;
    }
}




